package com.icoolkj.learn.juc.base;

import lombok.extern.slf4j.Slf4j;

/**
 * @author icoolkj
 * @version 1.0
 * @description 中断机制案例：中断正常运行的线程，不会清空中断状态
 * @createDate 2025/03/04 13:33
 */
@Slf4j
public class ThreadInterruptDemo {
    public static void main(String[] args) {
        Thread t1 = new Thread(new Runnable() {
            @Override
            public void run() {
                while (true) {
                    Thread current = Thread.currentThread();
                    boolean isInterrupted = current.isInterrupted();
                    if (isInterrupted) {
                        log.info("中断状态：{}", isInterrupted);
                        break;
                    }
                }
            }
        },"t1");

        t1.start();

        // 中断线程 t1
        t1.interrupt();
        log.info("中断状态：{} ", t1.isInterrupted());

    }
}
